﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace CDHunter.Manager
{
    public class PathManager
    {
        /// <summary>
        /// Generate Directory
        /// </summary>
        /// <param name="directoryName"></param>
        public static void GenerateDirectory(string directoryName)
        {
            if (!Directory.Exists(directoryName))
            {
                try
                {
                    Directory.CreateDirectory(directoryName);
                }
                catch (Exception Ex)
                {
                    throw Ex;
                }
            }
        }

        /// <summary>
        /// Get XMLFile Path
        /// </summary>
        /// <param name="xmlFileName"></param>
        /// <returns></returns>
        public static string GetXMLFilePath(string outPath, string xmlFileName)
        {
            string xmlFilePath;

            //Check If File Name Contains any Invalid Chars, and Replace them.
            if (xmlFileName.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0)
            {
                xmlFileName = xmlFileName.Replace('\\', '-').Replace('/', '-').Replace(':', '-').Replace('"', '-').Replace('|', '-').Replace('<', '-').Replace('>', '-');
            }

            if (outPath.LastIndexOf("\\") < outPath.Length - 1)
            {
                xmlFilePath = outPath + "\\" + xmlFileName + ".xml";
            }
            else
            {
                xmlFilePath = outPath + xmlFileName + ".xml";
            }

            return xmlFilePath;
        }
    }
}
